#@layoutT('')
#define main()
<div class="container-wrap">

    <table id="maingrid" lay-filter="maingrid"></table>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" id="deleteBtn_">批量删除</button>
            <button id='refreshBtn_' class="layui-btn  layui-btn-sm">
                <i class="layui-icon">&#xe669;</i> 刷新
            </button>

        </div>
    </script>
</div>
#end

#define js()
    <script>
        var userCode="#(vs.code)";
        layui.use(['upload'], function () {
            var $ = layui.jquery
                ,upload = layui.upload;
            gridArgs.title = '';
            gridArgs.dataId = 'id';
            gridArgs.deleteUrl = '#(path)/user/upload/file/delete';
            gridArgs.updateUrl = '#(path)/user/upload/file/edit/';
            gridArgs.addUrl = '#(path)/user/upload/file/add';
            gridArgs.gridDivId = 'maingrid';
            initGrid({
                id: 'maingrid'
                , elem: '#maingrid'
                , toolbar: '#toolbar'
                , cellMinWidth: 100
                , cols: [[
                    {title: '主键', field: 'id', width: 35, checkbox: true},
                    {title: '序号', type: 'numbers', width: 35},
                    {title: '用户名', field: 'user_code'},
                    {title: '文件名称', field: 'name'},
                    {title: '激活码', field: 'active_code'},
                    {title: '唯一标识', field: 'identifier'},
                    {title: '应用名称', field: 'app_name'},
                    {title: '应用版本', field: 'app_version'},
                    {title: '文件类型', field: 'type', templet: '#numToFileType'},
                    {title: '运行时间', field: 'run_time', edit: 'text'},
                    {title: '创建时间', field: 'create_time'},
                    {title: '操作',fixed:'right',width : 180,align : 'left', templet: function(d){
                        let str = '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>'
                        if(userCode === "superadmin") {
                            str += '<a class="layui-btn layui-btn-xs up_file"  value="'+d.id+'">替换文件</a>';
                        }
                        str +=' <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                        return str;
                   }
                }

                ]]
                , done: function(res, curr, count){//表格加载完成后，对上传按钮进行渲染
                    var tableId = this.id;
                    var tableElem = this.elem;
                    //table render出来实际显示的table组件
                    var tableViewElem = tableElem.next();
                    //渲染当前页面的所有upload组件
                    upload.render({
                        elem: tableViewElem.find('.up_file')
                        ,url: '/user/upload/file/uploadFile'
                        ,accept: 'file'
                        ,data:{}
                        ,before: function(obj){ //obj包含信息，跟choose回调完全一致。在传值之前先获取id
                            var tableElem = this.item;
                            id = tableElem.attr('value');
                            layer.load(); //上传loading
                        }
                        ,data: {
                            id: function () {//data中写值的时候，要用动态获取的方式，即写个function的方式，不然直接写获取不到相应的值。
                                return id;
                            }
                        }
                        ,done: function (res) {
                            layer.closeAll('loading'); //关闭loading
                            layer.msg('上传成功');
                        }
                        ,error: function(index, upload){
                            layer.closeAll('loading'); //关闭loading
                            layer.msg('上传失败，请重试');
                        }
                    });
                }
                , url: "#(path)/user/upload/file/list"
                , searchForm: 'searchForm'
            });
        });
    </script>


    <script type="text/html" id="numToFileType">
        #[[
        {{# if(d.type==1){ }}
        普通场景
        {{# } }}

        {{# if(d.type==2){ }}
        昙花场景
        {{# } }}
        ]]#
    </script>

#end

#define layuiFunc()
    //监听单元格编辑
    table.on('edit(maingrid)', function(obj){
        var value = obj.value //得到修改后的值
        ,data = obj.data //得到所在行所有键值
        ,field = obj.field; //得到字段
        var params="userUploadFile."+field+"="+value;

        $.post("#(path)/user/upload/file/updateFieldValue?"+params
            ,param({
            'userUploadFile.id' : data.id
        })
        ,function(feedback){
            $(".layui-laypage-btn").click();
            layer.msg(feedback.msg);
        });
    });
#end






